package com.xiaomaoguai.redis.sub;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import javax.annotation.Resource;

/**
 * @ FileName: RedisMessageListener.java
 * @ Author: WeiHui-Z
 * @ Date: 2017/4/20 19:42
 * @ Version: v1.0.0
 */
public class RedisMessageListener implements MessageListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(RedisMessageListener.class);

    @Resource
    private StringRedisSerializer stringRedisSerializer;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String channel = stringRedisSerializer.deserialize(message.getChannel());
        LOGGER.info("当前频道:[{}]", channel);
    }
}
